package com.healthcare.client.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.healthcare.client.form.ApplyGroupForm;
import com.healthcare.client.pojo.Group;
import com.healthcare.client.pojo.Patient;
import com.healthcare.client.service.GroupService;
import com.healthcare.client.vo.DoctorConsultationlListVo;
import com.healthcare.client.vo.DoctorMonadVo;
import com.healthcare.common.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 会诊申请 前端控制器
 * </p>
 *
 * @author 新华医院转诊联盟
 * @since 2020-04-13
 */
@Api(tags = "前台会诊管理")
@RestController
@RequestMapping("/client/group")
public class GroupController {

    @Autowired
    private GroupService groupService;

    @ApiOperation("申请会诊")
    @PostMapping(value = "applyGroup")
    public Result applyGroup(
            @ApiParam(name = "applyGroupForm", value = "申请会诊表单", required = true)
            @RequestBody ApplyGroupForm applyGroupForm){
        Map<String,Object> map = groupService.addGroupInfo(applyGroupForm);
        return Result.ok().data("datas",map);
    }

    @ApiOperation("查询会诊列表数据")
    @GetMapping("getGroupListVo/{page}/{size}/{identity}/{sortType}/{patientname}")
    public Result getGroupListVo(@PathVariable Integer page,@PathVariable Integer size,@PathVariable Integer identity,
                                 @PathVariable Integer sortType,@PathVariable String patientname){
        PageInfo pageInfo = groupService.getGroupListVo(page,size,identity,sortType,patientname);
        return  Result.ok().data("datas",pageInfo);
    }

    @ApiOperation("根据会诊id查询会诊单数据")
    @PostMapping("getDoctorMonadVoList/{groupId}")
    public Result getDoctorMonadVoList(
            @ApiParam(name = "groupId", value = "会诊id", required = true)
            @PathVariable Integer groupId){
        List<DoctorMonadVo> list =  groupService.getDoctorMonadVoList(groupId);
        return Result.ok().data("datas",list);
    }

    @ApiOperation("取消预约会诊")
    @PostMapping("cancelAppointment/{groupId}")
    public Result cancelAppointmentConsultation(
            @ApiParam(name = "groupId", value = "会诊id", required = true)
            @PathVariable Integer groupId){
        groupService.cancelConsultation(groupId);
        return Result.ok().message("已取消预约");
    }

    @ApiOperation("完成会诊")
    @PostMapping("accomplishGroup/{groupId}/{identity}")
    public Result accomplishGroup(
            @ApiParam(name = "groupId", value = "会诊id", required = true)
            @PathVariable Integer groupId,
            @ApiParam(name = "identity", value = "身份", required = true)
            @PathVariable Integer identity){
        groupService.accomplishGroup(groupId,identity);
        return Result.ok().message("完成会诊");
    }

    @ApiOperation("获得重新预约会诊的信息")
    @GetMapping(value = "getReapplyGroupInfo/{groupId}")
    public Result getReapplyGroupInfo(
            @ApiParam(name = "groupId", value = "会诊id", required = true)
            @PathVariable Integer groupId){
        Map<String,Object> map = groupService.getGroupPatientInfo(groupId);
        return Result.ok().data("datas",map);
    }

    @ApiOperation("拒绝会诊")
    @PostMapping("refuseGroup/{groupId}/{groupRemark}")
    public Result refuseGroup(
            @ApiParam(name = "groupId", value = "会诊id", required = true)
            @PathVariable Integer groupId,
            @ApiParam(name = "groupRemark", value = "拒绝理由", required = true)
            @PathVariable String groupRemark){
        groupService.refuseGroup(groupId,groupRemark);
        return Result.ok().message("拒绝会诊");
    }

    @ApiOperation("撤销操作")
    @PostMapping("revocationGroupOperation/{groupId}")
    public Result revocationGroupOperation(
            @ApiParam(name = "groupId", value = "会诊id", required = true)
            @PathVariable Integer groupId){
        groupService.revocationGroupOperation(groupId);
        return Result.ok().message("撤销操作");
    }

    @ApiOperation("分诊操作")
    @PostMapping("triageGroup")
    public Result triageGroup(
            @ApiParam(name = "group", value = "会诊信息", required = true)
            @RequestBody Group group){
        groupService.triageGroup(group);
        return Result.ok().message("分诊操作");
    }

    @ApiOperation("撤销分诊")
    @PostMapping("revocationTriageGroup/{groupId}")
    public Result revocationTriageGroup(
            @ApiParam(name = "groupId", value = "会诊id", required = true)
            @PathVariable Integer groupId){
        groupService.revocationTriageGroup(groupId);
        return Result.ok().message("撤销分诊");
    }

}

